package edu.tapestry.iddb.client.pages.userIDDB;

import iddb.AbstractResponse;
import iddb.OkResponse;

import org.apache.tapestry5.annotations.ApplicationState;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;

import edu.tapestry.iddb.client.entities.UserIDDB;
import edu.tapestry.iddb.client.pages.ErrorPage;
import edu.tapestry.iddb.client.pages.OKPage;
import edu.tapestry.iddb.client.webService.CommandsGenerator;
import edu.tapestry.iddb.client.webService.IDDBProxy;

public class RegisterUserIDDB {

	@Property
	@Persist
	private UserIDDB userIDDB;

	@ApplicationState
	private IDDBProxy proxy;
	
	
	@InjectPage
	private ErrorPage error;
	
	@InjectPage
	private OKPage ok;

	
	Object onActionFromRegister() {

		AbstractResponse resp = proxy.execute(CommandsGenerator.createRegister(
				userIDDB.getUsername(), userIDDB.getPasswd(), userIDDB.getEmail()));


		if (resp instanceof OkResponse){
			return ok.initialize(resp);
		}
		else {
			return error.initialize(resp);
		}
	}
}
